<template>
  <div class="admin_address_wrap">
    <div class="fixd_wrap">
      <back :title="title"></back>
    </div>
    <div class="orders_wrap">

      <orderList :dataList="data_list" @cancle_get_order_list="cancle_get_order_list"></orderList>
      <div v-if="is_null" class="hint_wrap">
        没有订单...
      </div>
      <div v-if="loading" class="hint_wrap">
        加载中...
      </div>
      <div v-if="!is_more&&!is_null" class="hint_wrap">
        没有更多了...
      </div>
    </div>
      <router-view @get_order_list="page=1,get_order_list()" @cancle_get_order_list="cancle_get_order_list"></router-view>
  </div>
</template>

<script>
  import back from 'components/back'
  import {stop_slider} from 'assets/base/base'
  import {get_cookie} from 'assets/cookie/cookie'
  import {get_address_list} from 'api/address'
  import orderList from  'components/orderList'
  import {get_order_list} from  'api/order'
  import {w_scroll_top} from 'assets/dom/dom'

  export default {
    name: "",
    props:[],
    data(){
      return{
        page:1,
        loading:false,
        is_more:true,
        data_list:[],
        is_null:false,
        title:'',
        show_cancle:false
      }
    },
    created(){

    },
    activated(){
      this.type=this.$route.query.type
      this.loading=true
      this.is_null=false
      this.is_more=true
      if(!this.type){
        this.$router.back()
        return
      }

      switch (this.type){
        case '0':this.title='待付款订单'
          break
        case '1':this.title='待发货订单'
          break
        case '2':this.title='待收货订单'
          break
        case '4':this.title='待评价订单'
          break
      }
      this.data_list=[]
      this.page=1
    this.get_order_list()
    },
    mounted(){
      this.brand_wrap_scroll()
    },
    computed:{

    },
    methods:{
      brand_wrap_scroll() {

        this.$parent.scroll_name_myOrder = () => {
          if ((document.body.clientHeight - document.documentElement.clientHeight <= w_scroll_top() + 320&&!this.loading)) {
           if(this.is_more&&this.$route.path === "/myOrder"){
             this.loading=true
             this.get_order_list()
           }

          }
        }
        window.removeEventListener("scroll", this.$parent.scroll_name_myOrder);
        window.addEventListener("scroll", this.$parent.scroll_name_myOrder);

      },
      get_order_list(){
        get_order_list({
          tp:this.type,
          token:get_cookie('key'),
          page:this.page
        }).then(res=>{
          if(res.status===200&&res.data.resStatus===0) {
            this.loading=false
            this.is_more=res.data.data.isMore
            console.log(res.data.data)
            if(this.page===1){
              this.data_list=res.data.data.list
            }else{
              this.data_list=this.data_list.concat(res.data.data.list)
            }
            if(res.data.data.isMore){
              this.page++
            }
          }else{
            this.is_more=false
            this.is_null=true
            this.data_list=[]
            this.loading=false
          }
        })
      },
      cancle_get_order_list(){
        this.page=1
        this.get_order_list()
      }
    },
    components:{
      back,
      orderList
    }
  }
</script>

<style scoped lang="scss">

  .fixd_wrap{
    max-width: 768px;
    margin: 0 auto;
    position: relative;
    z-index: 10;
  }
  .orders_wrap{
    height: 100%;
    padding-top: 43px;
    padding-bottom: 27px;
  }
  .hint_wrap{
    color: #999;
    padding-top: 15px;
  }
</style>
